package com.xy.user.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.user.Skill;
import com.xy.user.service.ISkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 技能Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/skill")
public class SkillController extends BaseController
{
    @Autowired
    private ISkillService skillService;

    /**
     * 查询技能列表
     */
    @RequiresPermissions("user:skill:list")
    @GetMapping("/list")
    public TableDataInfo list(Skill skill)
    {
        startPage();
        List<Skill> list = skillService.selectSkillList(skill);
        return getDataTable(list);
    }

    /**
     * 导出技能列表
     */
    @RequiresPermissions("user:skill:export")
    @Log(title = "技能", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Skill skill)
    {
        List<Skill> list = skillService.selectSkillList(skill);
        ExcelUtil<Skill> util = new ExcelUtil<Skill>(Skill.class);
        util.exportExcel(response, list, "技能数据");
    }

    /**
     * 获取技能详细信息
     */
    @RequiresPermissions("user:skill:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(skillService.selectSkillById(id));
    }

    /**
     * 新增技能
     */
    @RequiresPermissions("user:skill:add")
    @Log(title = "技能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Skill skill)
    {
        return toAjax(skillService.insertSkill(skill));
    }

    /**
     * 修改技能
     */
    @RequiresPermissions("user:skill:edit")
    @Log(title = "技能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Skill skill)
    {
        return toAjax(skillService.updateSkill(skill));
    }

    /**
     * 删除技能
     */
    @RequiresPermissions("user:skill:remove")
    @Log(title = "技能", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(skillService.deleteSkillByIds(ids));
    }
}
